package com.minyifang.wcspf.work.ui.home.presenter;

import com.minyifang.wcspf.common.base.BasePresenter;
import com.minyifang.wcspf.common.config.network.Constants;
import com.minyifang.wcspf.common.config.network.RetrofitHelper;
import com.minyifang.wcspf.common.config.user.UserManager;
import com.minyifang.wcspf.work.model.HttpRespond;
import com.minyifang.wcspf.work.ui.home.model.SearchBean;
import com.minyifang.wcspf.work.ui.home.view.SearchView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class SearchPresenter extends BasePresenter<SearchView> {
    public void getHotSearch() {
        JSONObject jsonData = Constants.getJsonData(null, null);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getHotSearchList(requestBody), hotSearchBeanHttpRespond -> getView().showHotSearchList(hotSearchBeanHttpRespond));
    }

    public void getSearchList(String content) {
        Map<String, Object> map = new HashMap<>();
        map.put("name", content);
        JSONObject jsonData = Constants.getJsonData(map, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService()
                .getSearchList(requestBody), searchBeanHttpRespond -> getView().showSearchList(searchBeanHttpRespond));
    }
}
